package com.lizemin.monitor.client.interceptor;

import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author lzm
 * @date 2025/6/9 20:24
 * @description
 */
public class ApiCounter {

    public static final ConcurrentHashMap<String, AtomicInteger> API_COUNTER = new ConcurrentHashMap<>();

    /**
     * 添加接口调用次数
     *
     * @param api 接口名称
     */
    public static void add(String api) {
        if (api == null || api.isEmpty()) {
            throw new RuntimeException("api不可为空！");
        }
        API_COUNTER.computeIfAbsent(api, k -> new AtomicInteger(0)).incrementAndGet();
    }

    /**
     * 获取接口调用次数
     *
     * @return 接口调用次数
     */
    public static ConcurrentHashMap<String,AtomicInteger> getApiCounters() {
        return API_COUNTER;
    }

}
